<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <% include header.ejs%>
    <title>categorys_edit</title>
</head>

<body>
  <% include nav.ejs%>
    <div class="container mt-3">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            <div class="row">
              <div class="col-md-12 mb-3">
                <label for="firstName">分类名称</label>
                <input type="text" class="form-control" id="firstName" value="<%= name%>" placeholder="请输入分类名称">
                <div class="invalid-feedback">
                  Valid first name is required.
                </div>
              </div>
              <div class="col-md-12 mb-3">
                <button type="button" name="" id="btn-submit" class="btn btn-dark btn-lg btn-block">提交</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
</body>
<script>
    var module_dir = "<%= module_dir%>";
    var id = "<%= id%>"
 </script>
<script>
  $(function(){
    $('#btn-submit').on('click',function(){
      var name = $('#firstName').val()
      if(name){
        $axios.post(`${module_dir}/categorys/edit`,{
            name,
            id
          }).then(resp=>{
            if(resp.status==1){
              window.location=`${module_dir}/categorys`
            }
          })
      }else{
        alert('请输入分类名称')
      }
      
    })
  })
</script>

</html>